package com.xr.core.system.entity.userModule;

import cn.hutool.core.lang.RegexPool;
import com.baomidou.mybatisplus.annotation.SqlCondition;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.xr.core.system.common.base.BaseEntity;
import com.xr.core.system.common.constants.Regular;
import com.xr.core.system.common.groups.Save;
import com.xr.core.system.common.groups.Update;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;

/**
 * 总后台用户表(User)表实体类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class User extends BaseEntity {

    private static final long serialVersionUID = -991183859355000223L;

    /**
     * 账户
     */
    @NotBlank(message = "用户名不能为空", groups = Save.class)
    @JsonProperty("acc")
    private String account;

    /**
     * 密码
     */
    @NotBlank(message = "密码不能为空", groups = Save.class)
    @Pattern(regexp = Regular.PASSWORD, message = Regular.PASSWORD_MASSAGE, groups = {Save.class, Update.class})
    @JsonProperty(value = "pwd", access = JsonProperty.Access.WRITE_ONLY)
    private String password;

    /**
     * 姓名
     */
    @TableField(condition = SqlCondition.LIKE_RIGHT)
    @Length(max = 10, groups = {Save.class, Update.class})
    @NotBlank(message = "姓名不能为空", groups = Save.class)
    @JsonProperty("nick")
    private String name;

    /**
     * 邮箱
     */
    @Email(message = "请输入正确邮箱格式", groups = {Save.class, Update.class})
    @JsonProperty("mail")
    private String email;

    /**
     * 手机号码
     */
    @Pattern(regexp = RegexPool.MOBILE, message = "请输入正确手机格式", groups = {Save.class, Update.class})
    @JsonProperty("number")
    private String phone;

    /**
     * 是否为内置
     */
    @JsonProperty("init")
    private Boolean initial;

    /**
     * 是否启用 1 启用 0 禁用
     */
    @JsonProperty("ena")
    private Boolean enable;

    /**
     * 用户头像
     */
    @JsonProperty("userAvatar")
    private String userAvatar;

    /**
     * 所在部门
     */
    @JsonProperty("departmentName")
    private String departmentName;

}

